package com.example.nonacademic_education.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.example.nonacademic_education.constant.Constant;
import com.example.nonacademic_education.entity.Msg;
import com.example.nonacademic_education.service.impl.MsgServiceImpl;
import com.example.nonacademic_education.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("msg")
public class MsgController {
    //消息管理
    //      发送消息。
    //      历史消息记录。
    @Resource
    private MsgServiceImpl msgService;
    //接口：
    //消息历史记录：接收者Id进行查询，是否查阅、优先级、时间排序
    @GetMapping("historyMsg")
    @SaCheckRole(Constant.STUDENT)
    public R historyMsg(Long recipientId,Integer page,Integer size,String content,Integer isRead){
        return msgService.historyMsg(recipientId,page,size,content,isRead);
    }
    //发送消息：消息类型
    //todo:考虑到服务器压力，这里不实现实时通知，而是登录之后，获取新消息；实现：websocket及时发送？
    @PostMapping("sendMsg")
    @SaCheckRole(Constant.NORMAL_ADMIN)
    public R sendMsg(@RequestBody Msg msg){
        return msgService.sendMsg(msg);
    }
    //已读消息
    @PutMapping("readMsg")
    @SaCheckRole(Constant.STUDENT)
    public R readMsg(Long msgId){
        return msgService.readMsg(msgId);
    }
    //删除消息
    //@DeleteMapping("delMsg")
    //@SaCheckRole(Constant.NORMAL_ADMIN)
    public R delMsg(Long msgId){
        return msgService.delMsg(msgId);
    }
    //未读消息
    @GetMapping("getUnread")
    @SaCheckRole(Constant.STUDENT)
    public R getUnread(Long recipientId){
        return msgService.getUnread(recipientId);
    }
    //@GetMapping("searchContacts")
    //@SaCheckRole(Constant.STUDENT)
    public R searchContacts(String name){
        return msgService.searchContacts(name);
    }
}
